<?php

class User_Api_Config
{
	/**
	 * @param array
	 */
	protected $_vars = array();

	/**
	 * @param string $table name
	 */
	protected $_table = NULL;

	/**
	 * default constructor
	 */
	function __construct()
	{
		$this -> _table = Nuo::getT('user_config');
	}

	/**
	 * @return array
	 */
	public function load($userId)
	{
		return Database::instance() -> fetchPairs('select item_name, item_value from ' . $this -> _table);
	}

	/**
	 * @param string $name
	 * @param mixed $value
	 * @return mixed
	 */
	function read($userId, $name, $value = NULL)
	{
		if (!isset($this -> _vars[$userId]))
		{
			$this -> _vars[$userId] = $this -> load($userId);
		}

		if (!isset($this -> _vars[$userId][$name]))
		{
			return $value;
		}

		return $this -> _vars[$userId][$name];
	}

}
